package com.ant.requestsecurity.configure;

import com.ant.requestsecurity.interceptor.ServerProtectInterceptor;
import com.ant.requestsecurity.properties.CloudRequestSecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

public class CloudSecurityInterceptorConfigure implements WebMvcConfigurer {
    private CloudRequestSecurityProperties securityProperties;

    @Autowired
    public void setSecurityProperties(CloudRequestSecurityProperties securityProperties){
        this.securityProperties = securityProperties;
    }

    public HandlerInterceptor serverProtectInterceptor() {
        ServerProtectInterceptor interceptor = new ServerProtectInterceptor();
        interceptor.setSecurityProperties(securityProperties);
        return interceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(serverProtectInterceptor());
    }
}
